package window;

import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.functions.windowing.ProcessWindowFunction;
import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
import org.apache.flink.util.Collector;

/**
 * Create by zhh on 2022/9/13.
 *  * @param <IN> DataStream中每个元素的类型
 *  * @param <OUT> The type of the output value.
 *  * @param <KEY> The type of the key.
 *  * @param <W> TimeWindow
 */
public class ZHProcessWindowFunction extends ProcessWindowFunction<Tuple2<String,Integer>,String,String, TimeWindow> {

    @Override
    public void process(String s, Context context, Iterable<Tuple2<String, Integer>> elements, Collector<String> out) throws Exception {
        System.out.println("s = " + s + ", context = " + context + ", elements = " + elements + ", out = " + out);
        System.out.println("------process invoked-------");
        int maxValue = Integer.MIN_VALUE;
        for (Tuple2<String,Integer> element:elements){
            maxValue = Math.max(element.f1,maxValue);
        }
        out.collect("当前窗口的最大值是："+maxValue);
    }
}
